<template>
  <div class="app-container">
    <el-row :gutter="20" class="toolbar" type="flex" justify="space-between">
      <!-- 左侧组合 -->
      <!--      <el-col :span="16">-->
      <!--        <el-row :gutter="15">-->
      <!--          <el-col :span="10">-->
      <!--            <el-input-->
      <!--                v-model="searchKey"-->
      <!--                placeholder="输入应用名称搜索"-->
      <!--                @keyup.enter.native="handleSearch">-->
      <!--              <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>-->
      <!--            </el-input>-->
      <!--          </el-col>-->
      <!--        </el-row>-->
      <!--      </el-col>-->

    </el-row>
    <!-- 数据表格 -->
    <el-table
        :data="userList"
        border
        stripe
        style="width: 100%"
        class="data-table">
      <el-table-column
          type="index"
          label="序号"
          width="60"
          align="center">
      </el-table-column>

      <el-table-column
          prop="userId"
          label="用户id"
          min-width="120">
      </el-table-column>

      <el-table-column
          prop="account"
          label="用户账户"
          min-width="120">
      </el-table-column>

      <el-table-column
          prop="lastLoginTime"
          label="最后登录时间"
          min-width="120">
      </el-table-column>

      <el-table-column
          prop="lastLoginIp"
          label="最后登录IP"
          min-width="120">
          <template v-slot="scope">
            {{ scope.row.lastLoginIp || '未知' }}
          </template>
      </el-table-column>

      <el-table-column
          prop="lastLoginDevice"
          label="最后登录的设备"
          min-width="120">
      </el-table-column>


    </el-table>


     <!-- 分页 -->
    <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>


  </div>

</template>

<script>
import {queryUserInfoPage} from '@/api/gateway-user-manage'

export default {
  data() {
    return {
      userList: [],
      sysAppId: '',
      currentPage: 1, // 当前页码
      pageSize: 10,   // 每页显示条数
      total: 0        // 总记录数
    }
  },
  mounted() {
    this.sysAppId = this.$route.query.id
    this.loadAppData()
  },
  methods: {
    // 加载数据方法
    async loadAppData() {
      try {
        const params = {
          id: this.sysAppId,
          page: this.currentPage, // 添加分页参数
          size: this.pageSize     // 添加分页参数
        }
        const {data} = await queryUserInfoPage(params)
        this.userList = data.records
        this.total = data.total // 更新总记录数
      } catch (error) {
        console.error('数据加载失败:', error)
      }
    },
    handleSizeChange(newSize) {
      this.pageSize = newSize
      this.loadAppData()
    },
    handleCurrentChange(newPage) {
      this.currentPage = newPage
      this.loadAppData()
    },
    async handleConfig(row) {
      this.$router.push({name: 'user-permission-group', query: {id: row.id}})
    },
  }
}
</script>

<style scoped>

/* 新增样式 */
.el-dialog__body {
  padding: 20px 30px;
}

.el-form-item {
  margin-bottom: 22px;
}

.el-textarea {
  resize: vertical;
}

.toolbar {
  margin-bottom: 20px;
}

.search-input {
  margin-right: 10px;
}

.data-table {
  margin-top: 15px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}

.text-right {
  text-align: right;
}

.detail-dialog .el-form-item {
  margin-bottom: 15px;
}

.detail-dialog .el-form-item span {
  font-weight: bold;
  color: #333;
}

.detail-dialog .dialog-footer {
  text-align: right;
  padding: 10px 0;
}

.detail-dialog .el-dialog__body {
  padding: 20px 30px;
  background-color: #f9f9f9;
  border-radius: 8px;
}
</style>